package com.object.module.cbb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.object.configuration.utils.PageUtils;
import com.object.configuration.utils.Query;
import com.object.dao.cbb.CbbSortDao;
import com.object.module.cbb.entity.CbbSortEntity;
import com.object.module.cbb.entity.CddShopEntity;
import com.object.module.cbb.service.CbbSortService;
import com.object.module.cbb.service.CddShopService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("cbbSortService")
public class CbbSortServiceImpl extends ServiceImpl<CbbSortDao, CbbSortEntity> implements CbbSortService {

    @Autowired
    private CddShopService cddShopService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<CbbSortEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (StringUtils.isNotEmpty(key)) {
             wrapper.eq("st_name",key);
        }
        IPage<CbbSortEntity> page = this.page(
                new Query<CbbSortEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<CbbSortEntity> listAll() {
        List<CbbSortEntity> list = list();
        for (CbbSortEntity cbbSortEntity : list) {
            QueryWrapper<CddShopEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("st_id", cbbSortEntity.getStId());
            List<CddShopEntity> list1 = cddShopService.list(wrapper);
            cbbSortEntity.setShops(list1);
        }
        return list;
    }

}